package com.ruoyi.tfjData.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.tfjData.domain.plat.DataTfj;
import com.ruoyi.tfjData.domain.plat.TfjChartRespDTO;
import com.ruoyi.tfjData.domain.report.TfjReportReqDTO;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tfjData.service.IDataTfjService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通风机测试结果Controller
 * 
 * @author ruoyi
 * @date 2023-11-27
 */
@RestController
@RequestMapping("/tfjData/all")
@Api(value="通风机-测试",tags = "通风机-测试接口")
public class DataTfjController extends BaseController
{
    @Autowired
    private IDataTfjService dataTfjService;

    /**
     * 查询通风机测试结果列表
     */
    @PreAuthorize("@ss.hasPermi('tfjData:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(DataTfj dataTfj)
    {
        startPage();
        List<DataTfj> list = dataTfjService.selectDataTfjList(dataTfj);
        return getDataTable(list);
    }

    /**
     * 导出通风机测试结果列表
     */
    @PreAuthorize("@ss.hasPermi('tfjData:task:export')")
    @Log(title = "通风机测试结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataTfj dataTfj)
    {
        List<DataTfj> list = dataTfjService.selectDataTfjList(dataTfj);
        ExcelUtil<DataTfj> util = new ExcelUtil<DataTfj>(DataTfj.class);
        util.exportExcel(response, list, "通风机测试结果数据");
    }

    /**
     * 获取通风机测试结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('tfjData:task:query')")
    @GetMapping(value = "/{tfjId}")
    public AjaxResult getInfo(@PathVariable("tfjId") Long tfjId)
    {
        return success(dataTfjService.selectDataTfjByTfjId(tfjId));
    }

    /**
     * 获取单条通风机测试任务
     */
    @PreAuthorize("@ss.hasPermi('tfjData:task:query')")
    @GetMapping(value = "/getTfjTask/{dataTaskId}")
    @ApiOperation(value="查询单条通风机测试的所有测试项目数据")
    @ApiImplicitParam(paramType="query", name = "dataTaskId", value = "任务id", required = true, dataType = "Long")
    public AjaxResult getTfjTask(@PathVariable("dataTaskId") Long dataTaskId) throws Exception {
        return success(dataTfjService.selectTfjTaskDetail(dataTaskId));
    }

    /**
     * 新增通风机测试结果
     */
    @PreAuthorize("@ss.hasPermi('tfjData:task:add')")
    @Log(title = "通风机测试结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataTfj dataTfj)
    {
        return toAjax(dataTfjService.insertDataTfj(dataTfj));
    }

    /**
     * 通风机效图所需的数据
     *
     * @param tfjIds 测试数据ID
     * @return
     */
    @ApiOperation("通风机效图数据")
    @PreAuthorize("@ss.hasPermi('tfjData:task:query')")
    @GetMapping("/task/chart/{tfjIds}")
    public AjaxResult getChartElements(@PathVariable Long[] tfjIds) {
        TfjChartRespDTO chartData = dataTfjService.getChartData(tfjIds);
        return chartData != null ? AjaxResult.success(chartData) : AjaxResult.error();
    }

    /**
     * 修改通风机测试结果
     */
    @PreAuthorize("@ss.hasPermi('tfjData:task:edit')")
    @Log(title = "通风机测试结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataTfj dataTfj)
    {
        return toAjax(dataTfjService.updateDataTfj(dataTfj));
    }

    /**
     * 通风机数据变更
     */
    @PreAuthorize("@ss.hasPermi('tfjData:task:edit')")
    @Log(title = "通风机数据变更", businessType = BusinessType.UPDATE)
    @PutMapping("/modify")
    @ApiOperation(value="通风机数据变更")
    public AjaxResult modify(@RequestBody DataTfj dataTfj)
    {
        return success(dataTfjService.modifyTfjData(dataTfj));
    }

    /**
     * 根据任务id删除通风机测试结果
     */
    @PreAuthorize("@ss.hasPermi('tfjData:task:remove')")
    @Log(title = "根据任务id删除通风机测试结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{tfjId}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "tfjId", value = "通风机id", required = true, dataType = "Long"),
    })
    @ApiOperation(value="根据任务id删除通风机测试结果")
    public AjaxResult remove(@PathVariable("tfjId")Long tfjId)
    {
        return toAjax(dataTfjService.updateDataTfjByTfjId(tfjId));
    }

    /**
     * 根据任务id删除整条通风机测试结果
     */
    @PreAuthorize("@ss.hasPermi('tfjData:task:remove')")
    @Log(title = "根据任务id删除整条通风机测试结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/updateDataTfjByDataTaskId/{dataTaskId}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "dataTaskId", value = "任务id", required = true, dataType = "Long"),
            })
    @ApiOperation(value="根据任务id删除整条通风机测试结果")
    public AjaxResult updateDataTfjByDataTaskId(@PathVariable("dataTaskId")Long dataTaskId)
    {
        return toAjax(dataTfjService.updateDataTfjByDataTaskId(dataTaskId));
    }

    /**
     * 保存的通风机数据导入报告
     */
    @PreAuthorize("@ss.hasPermi('tfjData:import:query')")
    @PostMapping("/dataTfjImportReport")
    @ApiOperation(value="保存的通风机数据导入报告")
    public AjaxResult dataTfjImportReport(@ApiParam(name="测试项目结果数据",value="传入json格式",required=true)@RequestBody TfjReportReqDTO tfjReportReqDTO){

        return AjaxResult.success(dataTfjService.dataTfjImportReport(tfjReportReqDTO));
    }

    /**
     * 删除通风机测试结果
     */
    @PreAuthorize("@ss.hasPermi('tfjData:task:remove')")
    @Log(title = "通风机测试结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tfjIds}")
    public AjaxResult remove(@PathVariable Long[] tfjIds)
    {
        return toAjax(dataTfjService.deleteDataTfjByTfjIds(tfjIds));
    }
}
